package com.cwd.arm.application.service.write;

import com.cwd.arm.application.dto.pay.PayAddDto;
import com.cwd.arm.application.dto.pay.PayUpdateDto;
import com.cwd.arm.application.service.write.facade.PayWriteService;
import com.cwd.arm.domain.entity.PayEntity;
import com.cwd.arm.domain.repository.PayRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
* Description:现金支出
* Created on 2021年11月20日
* @author  yan
*/
@Repository
@Primary
public class PayWriteServiceImpl implements PayWriteService{

    @Autowired
    private PayRepository payRepository;

    @Transactional
    @Override
    public void save(PayAddDto addDto) {
        payRepository.save(convertToEntity(addDto));
    }

    @Transactional
    @Override
    public void update(PayUpdateDto updateDto) {
        payRepository.update(convertToEntity(updateDto));
    }

    @Transactional
    @Override
    public void del(Long id) {
        payRepository.del(id);
    }

    private PayEntity convertToEntity(PayAddDto dto){
        PayEntity payEntity = new PayEntity();
        BeanUtils.copyProperties(dto,payEntity);
        return payEntity;
    }

    private PayEntity convertToEntity(PayUpdateDto dto){
        PayEntity payEntity = new PayEntity();
        BeanUtils.copyProperties(dto,payEntity);
        return payEntity;
    }
}
